package com.niit.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.niit.domain.Leave_message;
import com.niit.service.ILeave_messageService;
import com.niit.service.impl.Leave_messageService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "LeaveMessageServlet", value = "/LeaveMessageServlet")
public class LeaveMessageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String lname = request.getParameter("username");
        String content = request.getParameter("content");
        String phone = request.getParameter("phone");



        Leave_message leave_message = new Leave_message();
        leave_message.setLname(lname);
        leave_message.setContent(content);
        leave_message.setPhone(phone);

        ILeave_messageService iLeave_messageService = new Leave_messageService();
        int i = iLeave_messageService.InsertLeaveMessage(leave_message);
        boolean flag;
        if(i>0){
            flag = true;
        }else{
            flag = false;
        }
        ObjectMapper mapper = new ObjectMapper();
        response.setContentType("application/json;charset=utf-8");
        mapper.writeValue(response.getOutputStream(), flag);


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
